package com.wh1200.mybatis.xmlless.resolver

import com.wh1200.mybatis.xmlless.enums.MethodType
import org.junit.jupiter.api.Test
import java.util.*
import kotlin.test.assertEquals

/**
 * Created by 吴昊 on 2024/1/15.
 */
class MethodTypeResolverTest {

  @Test
  fun resolveTypeFromName() {
    val stack = Stack<String>().apply {
      push("One")
      push("Find")
    }
    val result = MethodTypeResolver.resolveTypeFromName(
        stack
    )
    assertEquals(MethodType.Select, result)
    assert(stack.isEmpty())
  }

  @Test
  fun resolveTypeFromName2() {
    val stack = Stack<String>().apply {
      push("All")
      push("Find")
    }
    val result = MethodTypeResolver.resolveTypeFromName(
        stack
    )
    assertEquals(MethodType.Select, result)
    assert(stack.isEmpty())
  }

  @Test
  fun resolveTypeFromName3() {
    val stack = Stack<String>().apply {
      push("Id")
      push("By")
      push("Find")
    }
    val result = MethodTypeResolver.resolveTypeFromName(
        stack
    )
    assertEquals(MethodType.Select, result)
    assertEquals(2, stack.size)
  }
  @Test
  fun resolveTypeFromName4() {
    val stack = Stack<String>().apply {
      push("All")
      push("Update")
      push("Or")
      push("Save")
    }
    val result = MethodTypeResolver.resolveTypeFromName(
        stack
    )
    assertEquals(MethodType.InsertOrUpdate, result)
    assert(stack.isEmpty())
  }

  @Test
  fun resolveTypeFromName5() {
    val stack = Stack<String>().apply {
      push("All")
      push("List")
    }
    val result = MethodTypeResolver.resolveTypeFromName(
        stack
    )
    assertEquals(MethodType.Select, result)
    assert(stack.isEmpty())
  }

}
